app.controller('lineCustomerController', ['$scope', 'ajax', 'lineCustomService', 'Flash','sellService', 'SERVER_URL', function ($scope, ajax, lineCustomService, Flash,sellService, SERVER_URL) {

    $scope.queryData = {
        address_like : "",
        storeName_like: '',
        sellerCode:'',
        hasFirstOrder:''
    };
    //重置按钮
    $scope.reset=function(){
        $scope.queryData={};
        $scope.isclick=true;
    }
    // 客户列表
    function list(page) {
        lineCustomService.list({
            currentPage: page,
            pageSize: 10,
            address_like : $scope.queryData.address_like,
            storeName_like : $scope.queryData.storeName_like,
            sellerCode:$scope.queryData.sellerCode,
            hasFirstOrder:$scope.queryData.hasFirstOrder
        }).then(function (result) {
            $scope.data = result;
        });
    }

    list(1);

    //分页
    $scope.pageChanged = function (e) {
        list(e);
    };

    $scope.doQuery = function(x){
        if(angular.isUndefined(x) || $scope.isclick==true){
            list(1);
        }
        else{
            $scope.queryData.sellerCode= x.sellerCode;
            list(1);
        }
        $scope.isclick=false;
    };
    /*
     * 删除客户
     * parms id 客户id
     */
    $scope.delLineCustomer = function (id,name) {

        var returnKey = confirm("确认删除该客户");
        if(returnKey) {
            ajax.post({
                url: 'back/customer/delete',
                data: {customerId: id},
                debug: true
            }).then(function (e) {


                list($scope.data.currentPage);
                Flash.create('success', '删除成功', 'custom-class');


                //$state.go('admin.lineCustomer', null, {
                //    reload: true
                //});
            })
        }
    }


    //导出表格
    $scope.exportAllGoods = function(sellerCode){
        if(angular.isUndefined(sellerCode) ){
            location.href=SERVER_URL+'/back/customer/exportExcel?hasFirstOrder='+$scope.queryData.hasFirstOrder+'&sellerCode=';
        }
        else{
            location.href=SERVER_URL+'/back/customer/exportExcel?hasFirstOrder='+$scope.queryData.hasFirstOrder+'&sellerCode='+sellerCode.sellerCode;
        }
    }
    //导入表格




    //查询销售人员
    function listSell(page){
        sellService.list({
            currentPage: page,
            pageSize: 999
        }).then(function(result){
            console.log(result)
            $scope.seller = result.resultData;
        })
    };
    listSell(1);

}]);